#----------------------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(ezDrawPJ)

#----------------------------------------------------------------------------
# Specify the C++ standard 
#
set(CMAKE_CXX_STANDARD 20) 
set(CMAKE_CXX_STANDARD_REQUIRED True) 
set(CMAKE_BUILD_TYPE Debug)

#----------------------------------------------------------------------------
# Define macro PROJECT_SOURCE_DIR
add_definitions(-DPROJECT_SOURCE_DIR=\"${PROJECT_SOURCE_DIR}\")

#----------------------------------------------------------------------------
# Setup ROOT include directories and compile definitions
#
list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
find_package(ROOT REQUIRED)

# check ROOT version
if(ROOT_FOUND)
  STRING(REGEX MATCH "6.*" VERSION6MATCH ${ROOT_VERSION})
  if(NOT VERSION6MATCH)
    message(FATAL_ERROR "--> ERROR: ROOT 6 is required but not found")
  endif()
endif()

include(${ROOT_USE_FILE})

#----------------------------------------------------------------------------
# Find Yaml-cpp
#
find_package(yaml-cpp REQUIRED)

#----------------------------------------------------------------------------
# Locate sources and headers for this project
#
include_directories(${ROOTSYS}/include)
include_directories(${YAML_CPP_INCLUDE_DIRS})

#MESSAGE( ${PROJECT_SOURCE_DIR} )
include_directories(${PROJECT_SOURCE_DIR}/include)

file(GLOB_RECURSE sources "${PROJECT_SOURCE_DIR}/src/*.cpp")
file(GLOB_RECURSE headers "${PROJECT_SOURCE_DIR}/include/*.h")

#----------------------------------------------------------------------------
# Add the executable, and link it to the ROOT libraries
#
#add_executable(ezDraw ezDraw.cpp)
add_executable(ezDraw ezDraw.cpp ${sources} ${headers})
target_link_libraries(ezDraw ${ROOT_LIBRARIES} ${YAML_CPP_LIBRARIES})

#----------------------------------------------------------------------------
# Copy all scripts to the build directory, i.e. the directory in which we
# build My. This is so that we can run the executable directly because it
# relies on these scripts being in the current working directory.

set(SCRIPTS_AND_CARD
DrawOptions.yml
)

foreach(script ${SCRIPTS_AND_CARD})
  configure_file(
    ${PROJECT_SOURCE_DIR}/${script}
    ${PROJECT_BINARY_DIR}/${script}
    COPYONLY
  )
endforeach()

#----------------------------------------------------------------------------
# Add program to the project targets
# (this avoids the need of typing the program name after make)
#
add_custom_target(ezDrawPJ DEPENDS ezDraw)

#----------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
#
#set(CMAKE_INSTALL_PREFIX ../StarXP-install) 
#install(TARGETS starXP DESTINATION bin)